<?php


namespace app\platform\controller;


use data\service\Article;
use data\service\EnterpriseRegistration;

class Settled extends BaseController
{

    public function index()
    {
        if (request()->isAjax()) {
            $article = new EnterpriseRegistration();

            $page_index = request()->post('page_index', 1);
            $page_size = request()->post('page_size', PAGESIZE);
            $str = request()->post('name', '');
            $status = request()->post('status', '');
            if(!empty($str)){
                $condition['name'] = array(
                    "like",
                    "%" . $str . "%"
                );
            }

            if($status != ""){
                $condition['status'] = $status;
            }
            $article_list = $article->getSettledQuery($condition,$page_size=0,$page_index=0,$order = "");

            return $article_list;
        } else {
            $article = new EnterpriseRegistration();
            $article_list = $article->getSettledQuery($condition = [], $page_size = 0, $page_index = 0, $order = "");
            $this->assign('list', $article_list["data"]);
            return view($this->style . 'Settled/list');
        }
    }


    public function reject()
    {
        $id = request()->post('id');
        $status = request()->post('status');
        $reject_info = request()->post('reject_info');
        $article = new EnterpriseRegistration();
        $result = $article->saveSettledIn($id, $status,$reject_info);
        return json_encode(AjaxReturn(SUCCESS));

    }

    public function view($id){
        $article = new EnterpriseRegistration();
        $condition['id']=$id;
        $article_list = $article->findSettle($condition);
        $image = $article_list['image'];
        $article_list['image'] = "<img src=".$image." style = \"width: 371px;height: 377px;\" class=\"lazy_load\" data-original=".$image." />";
        $article_list['created_at']  = date('Y-m-d H:i:s',$article_list['created_at']);
        $article_list['updated_at']  = date('Y-m-d H:i:s',$article_list['updated_at']);
        $status = $article_list['status'];
        if($status == -1){
            $article_list['str_status'] = "<b style=\"color: red;\">拒绝</b>";

        }elseif($status == 0){
            $article_list['str_status'] ="<b style=\"color: grey;\">审核中</b>";

        }elseif($status == 1){
            $article_list['str_status'] = "<b style=\"color: green;\">审核确认</b>";

        }elseif($status == 2){
            $article_list['str_status'] = "<b style=\"color: green;\">审核确认</b>";

        }

        $this->assign('list', $article_list);
        return view($this->style . 'Settled/view');

    }
}